import { GCellRenderer } from "../../../../../../com/mui/controls/GCellRenderer";
import { TRuneGuide } from "../../../../../../Message/Db/Tables/TRuneGuide";
import { Language } from "../../../../../../extend/language/Language";
import { HTMLUtil } from "../../../../../../com/gengine/utils/HTMLUtil";
import { Alert } from "../../../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../../events/DataEvent";
import { EventName } from "../../../../mvc/EventName";
import { ResouceConst } from "../../../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../../../resource/ImagesConst";
import { GTextFormat } from "../../../../../common/GTextFormat";
import { FontUtil } from "../../../../../common/font/FontUtil";
import { GlobalStyle } from "../../../../../common/global/GlobalStyle";
import { ObjCreate } from "../../../common/ObjCreate";
import { BaseItem } from "../../../common/BaseItem";
import { ItemData } from "../../../../resource/info/ItemData";
import { RuneUtil } from "../RuneUtil";
import { GlobalClass } from "../../../../../../com/mui/core/GlobalClass";
import { GameDefConfig } from "../../../../resource/GameDefConfig";
import { ScaleBitmap } from "../../../../../../com/mui/display/ScaleBitmap";
import { GButton } from "../../../../../../com/mui/controls/GButton";
type int = number;
//class RuneGuideShopRender
    
    export  class RuneGuideShopRender extends GCellRenderer
    {
        constructor()
        {
            super();
            this.initUI();
            return;
        }

        /* internal  */onOptBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc2=null;
            var loc1=data as TRuneGuide;
            if (loc1) 
            {
                if (loc1.price != 0) 
                {
                    loc2 = Language.getString(26506) + HTMLUtil.addColor(loc1.price + Language.getString(26507), "#ffff00") + Language.getString(26508) + this._itemData.htmlName + "×" + loc1.sellNum + "<br>";
                }
                else 
                {
                    loc2 = Language.getString(26505) + this._itemData.htmlName + "×" + loc1.sellNum + "<br>";
                }
                loc2 = loc2 + Language.getString(26509);
                Alert.show(loc2, Language.getString(20055), Alert.OK | Alert.CANCEL, null, this.alertHandler);
            }
            return;
        }

        /* internal  */alertHandler(arg1: int): void
        {
            if (arg1 == Alert.OK) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.RuneGuideGetItem, data));
            }
            return;
        }

        protected initUI(): void
        {
            this._bg = ResouceConst.getScaleBitmap(ImagesConst.DisabledBg);
            this._bg.setSize(252, 117);
            addChild(this._bg);
            this._nameBg = ResouceConst.getScaleBitmap(ImagesConst.TileBg);
            this._nameBg.x = 5;
            this._nameBg.y = 10;
            this._nameBg.setSize(150, 24);
            addChild(this._nameBg);
            var loc1=new GTextFormat(FontUtil.songtiName, 15, GlobalStyle.color1Uint, true);
            this._nameTxt = ObjCreate.createTextField("", this._nameBg.x + 5, this._nameBg.y + 2, 120, 20, this, loc1);
            this._countTxt = ObjCreate.createTextField("", this._nameTxt.x + 90, this._nameTxt.y + 2, 50, 20, this);
            this._freeTxt = ObjCreate.createTextField(Language.getString(26510), 140, 40, 60, 30, this, loc1);
            this._oldPrice = ObjCreate.createTextField("", 110, 40, 120, 20, this);
            this._priceTxt = ObjCreate.createTextField("", this._oldPrice.x, this._oldPrice.y + 20, 120, 20, this);
            this._priceLine = new Object /* flash.display.Sprite */();
            this._priceLine.x = this._oldPrice.x + 50;
            this._priceLine.y = this._oldPrice.y + 2;
            this._priceLine.graphics.lineStyle(1, 16711680);
            this._priceLine.graphics.lineTo(20, 12);
            this._priceLine.graphics.endFill();
            addChild(this._priceLine);
            this._oldPriceBmp = new Object /* flash.display.Bitmap */();
            this._oldPriceBmp.x = 190;
            this._oldPriceBmp.y = 40;
            addChild(this._oldPriceBmp);
            this._priceBmp = new Object /* flash.display.Bitmap */();
            this._priceBmp.x = this._oldPriceBmp.x;
            this._priceBmp.y = this._oldPriceBmp.y + 20;
            addChild(this._priceBmp);
            this._itemBg = ResouceConst.getScaleBitmap(ImagesConst.PackItemBg);
            this._itemBg.width = 66;
            this._itemBg.height = 66;
            this._itemBg.x = 10;
            this._itemBg.y = 40;
            addChild(this._itemBg);
            this._item = new BaseItem();
            this._item.setSize(60, 60);
            this._item.x = this._itemBg.x + 3;
            this._item.y = this._itemBg.y + 3;
            addChild(this._item);
            this._optBtn = ObjCreate.createGButton(Language.getString(26511), 122, 80, 70, 24, this);
            this._optBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOptBtnClickHandler);
            this._optBtn.drawNow();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            super.data = arg1;
            loc1 = arg1 as TRuneGuide;
            this._itemData = new ItemData(loc1.itemCode);
            this._item.itemData = this._itemData;
            this._nameTxt.htmlText = this._itemData.htmlName;
            if (loc1.sellNum != 1) 
            {
                this._countTxt.htmlText = HTMLUtil.addColor("×" + loc1.sellNum, "#00ff00");
            }
            else 
            {
                this._countTxt.htmlText = RuneUtil.getRuneItemLevelName(this._itemData);
            }
            if (loc1.price == 0 && loc1.oldPrice == 0) 
            {
                this._freeTxt.visible = true;
                this._oldPrice.visible = false;
                this._oldPriceBmp.visible = false;
                this._priceBmp.visible = false;
                this._priceTxt.visible = false;
                this._priceLine.visible = false;
            }
            else 
            {
                this._freeTxt.visible = false;
                this._oldPrice.visible = true;
                this._oldPriceBmp.visible = true;
                this._priceBmp.visible = true;
                this._priceTxt.visible = true;
                this._priceLine.visible = true;
                this._oldPrice.htmlText = HTMLUtil.addColor(Language.getString(26512) + loc1.oldPrice, GlobalStyle.color1);
                this._priceTxt.htmlText = HTMLUtil.addColor(Language.getString(26513) + loc1.price, "#ffff00");
                this._oldPriceBmp.bitmapData = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitImg(loc1.sellUnit));
                this._priceBmp.bitmapData = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitImg(loc1.sellUnit));
            }
            return;
        }

        /* internal */ /* var */_bg: ScaleBitmap;

        /* internal */ /* var */_nameBg: ScaleBitmap;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_countTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_freeTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_oldPrice: Object /* flash.text.TextField */;

        /* internal */ /* var */_priceTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_oldPriceBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_priceBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_priceLine: Object /* flash.display.Sprite */;

        /* internal */ /* var */_itemBg: ScaleBitmap;

        /* internal */ /* var */_item: BaseItem;

        /* internal */ /* var */_itemData: ItemData;

        /* internal */ /* var */_optBtn: GButton;
    }
